﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Minestorm.Evolved.GameLogic
{
    public class MapInputStateHelper
    {
        private InputState _inputState;

        public MapInputStateHelper(InputState inputState)
        {
            _inputState = inputState;
        }

        private bool IsKeyDown(Keys key)
        {
            return _inputState.CurrentKeyboardStates[0].IsKeyDown(key);
        }

        private bool IsKeyUp(Keys key)
        {
            return _inputState.CurrentKeyboardStates[0].IsKeyUp(key);
        }

        private bool WasKeyDown(Keys key)
        {
            return _inputState.LastKeyboardStates[0].IsKeyDown(key);
        }

        private bool WasKeyUp(Keys key)
        {
            return _inputState.LastKeyboardStates[0].IsKeyUp(key);
        }

        private bool IsNewKeyPress(Keys key)
        {
            return IsKeyDown(key) && WasKeyUp(key);
        }

        private bool IsNewKeyRelease(Keys key)
        {
            return IsKeyUp(key) && WasKeyDown(key);
        }

        public bool PanRight()
        {
            PlayerIndex playerIndex;
            return IsNewKeyPress(Keys.Right) || _inputState.IsNewButtonPress(Buttons.LeftThumbstickRight, null, out playerIndex);
        }

        public bool PanLeft()
        {
            PlayerIndex playerIndex;
            return IsNewKeyPress(Keys.Left) || _inputState.IsNewButtonPress(Buttons.LeftThumbstickLeft, null, out playerIndex);
        }

        public bool PanUp()
        {
            return IsNewKeyPress(Keys.Up);
        }

        public bool PanDown()
        {
            return IsNewKeyPress(Keys.Down);
        }

        public bool ZoomIn()
        {
            return IsNewKeyPress(Keys.O);
        }

        public bool ZoomOut()
        {
            return IsNewKeyPress(Keys.L);
        }

        public bool PanToOrigin()
        {
            return IsNewKeyPress(Keys.Space);
        }
    }
}
